package org.snow001.lcy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InvokeKernel {

	public static Result invoke(Method method, Object target, Parameters parameters) throws IllegalArgumentException, IllegalAccessException,
			InvocationTargetException {
		if (null == method) {
			return null;
		}
		if (null == parameters) {
			return (Result) method.invoke(target, new Object[] {});
		} else {
			return (Result) method.invoke(target, new Object[] { parameters });
		}
	}

	public static Result invoke(Method method, Parameters parameters) throws IllegalArgumentException, IllegalAccessException,
			InvocationTargetException {
		return invoke(method, null, parameters);
	}

	public static Result invoke(InvokeKernelSupport support) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		if (null == support) {
			return null;
		}
		return invoke(support.getMethod(), support.getTarget(), support.getParameters());
	}
}
